package com.dycx.api.config;

import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.time.format.DateTimeFormatter;

/**
 * 拦截器
 */

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {


    /**
     * @return
     * @Bean注解 全局配置输入的日期格式，添加此处即可，配置文件无需添加date-format，
     * 项目内如有继承WebMvcConfigurationSupport，此方法将失效
     * @Bean <bean id="xxx"></bean>
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
        String dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
        String dateFormat = "yyyy-MM-dd";

        return builder -> {
            builder.simpleDateFormat(dateTimeFormat);
            builder.serializers(new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat)));
            builder.serializers(new LocalDateSerializer(DateTimeFormatter.ofPattern(dateFormat)));
        };
    }

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        //定位项目文件夹下的upload图片文件，作为静态资源目录
//        String UPL_PATH = System.getProperty("user.dir") + "/static/";
//        String CROSSDOMAIN_FILE = System.getProperty("user.dir") + "/crossdomain.xml";
//        //静态资源映射
//        registry.addResourceHandler("/static/**")
//                .addResourceLocations("file:" + UPL_PATH);
//
//        //静态资源映射
//        registry.addResourceHandler("/crossdomain.xml")
//                .addResourceLocations("file:" + CROSSDOMAIN_FILE);
//    }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
////         addPathPatterns("/**") 表示拦截所有的请求，
////         excludePathPatterns("/login", "/register") 表示除了登陆与注册之外，因为登陆注册不需要登陆也可以访问
//
////        //验证、储存登录信息
////        registry.addInterceptor(adminLoginInterceptor).addPathPatterns("/manage/**").excludePathPatterns(
////                "/manage/system/admin/login"
////        );
////
////        //验证操作权限
////        registry.addInterceptor(actionVerifyInterceptor).addPathPatterns("/manage/**")
////                .excludePathPatterns(
////                        "/manage/system/admin/login",
////                        "/manage/system/admin/exit",
////                        "/manage/system/admin/updatePassword",
////                        "/manage/system/role/getRoleMenu"
////                );
//
//
//    }


}

